#ifndef OUTPUT_H
#define OUTPUT_H

#include <QObject>
#include <QTimer>

class Output:public QObject
{
    Q_OBJECT
public:
    Output(int no);
//    Output(const Output &){

//    }
     struct Range
        {
            float lo;
            float hi;
            QString str(){return QString("[%1-%2]").arg(lo).arg(hi);}
        };

    union OutputData
    {
        float point;
        Range range;
    };
    enum Status
        {
            UNKNOW=-1,
            RESET=0,
            SET=1,

            GREEN = RESET,
            RED = SET
        };
    uint getNo() {return mNo;}
    void setOperation(int operation)
    {
         mOperation = operation;
    }
    uint getOperation()
    {
        return mOperation;
    }
    void setOptName(const QString& optName)
    {
        mOptName = optName;
    }
    QString getOptName()
    {
        return mOptName;
    }

    void setNormalStatus(uint status);

    uint normalStatus()
    {
        return mNormalStatus;
    }

    uint getDelayTime()
    {
        return mDelayTime;
    }

    uint getContinueTime()
    {
        return mContinueTime;
    }

    void setStartDly(int dly){
        mDelayTime = dly;
    }

    void setContinueTime(int time){
        mContinueTime = time;
    }

    Output::Status getStatus() {return mStatus;}
    void setRange(float hi,float lo);
    void setPoint(float);
    bool checkRange(float w);
    void checkPoint(float w);
    Range* getRange() {return &(mData.range);}
public slots:
    void setStatus(Output::Status status);

private slots:
    void startStatusSet();//触发设置状态
    void endStatusSet(); //结束设置状态即回到复位状态
private:
    void __setStatus(Status status);
    int mNo;
    int mOperation;
    uint mNormalStatus;
    uint mDelayTime;
    uint mContinueTime;
    Status mStatus;
    OutputData mData;
    QString mOptName;
    QTimer* mContinueTimer;
};

#endif // OUTPUT_H
